/* 
 * File:   Assignment1.h
 * Author: kartik
 *
 * Created on September 15, 2009, 8:04 PM
 */

#ifndef _ASSIGNMENT1_H
#define	_ASSIGNMENT1_H

#include "copyright.h"
#include "thread.h"
#include "list.h"
#include "synch.h"

//extern void Patient(int patientId);
//extern void Receptionist(int rec_id);


   
    
    void Patient(int patientId);
    void Receptionist(int Rec_Id);
    void DoorBoy(int id);
    void Hospital_Manager(int HM_id);
    void Doctor(int id);

    int GetMinValue(int arr[],int size);
    int GenerateRandomDoctorNumber(int high, int low);
    int GetDoctorForDoorBoy(int arr[], int size, int DB_Id);
    
    void InitilalizeRecep(int number);
    void InitializeDB(int number);
    void InitializeManager();
    void InitializeDoctor(int number);
    void InitializePatient(int number);
    void InitializeCashier(int number);
    void InitializePharma(int number);

    void Cashier(int number);
    void PharmacyClerk(int number);

    Condition **cashierControl;

    Lock* RecpLineLock;        //this lock is used to get in the shortest line
    int Num_of_receptionist; //Indicated the num of receptionist in simulation
    int* arr_RecLineCount;   //An Indexed based array indicating line count at each position
    Condition** arr_RecLineCV; //Array of condition variables for line of each recp
    Condition** arr_RecCV; //Array of condition variables one for each recp
    Lock** RecepLock;      //Array of pointer of locks each for one recep to have
                            //one to one interaction.

    Lock* tokenLock;        //Lock used by receptionist so patient can get the token
    int currentToken;       //Receptionist gives patient unique token number
    Lock* RecBreakLock;
    Condition* RecbreakCV;
    int* RecToken;

    //Variables needed for doorboy
    int* arr_DoctorLineCount;   //this tracks the number of patient in the doctors line
    Lock* DBLineLock;   //Lock for the doorboy line
    Lock* DoorBoyLock;
    Condition** arr_DoctorLineCV;
    int numOfDoctors;
    int* Doctor_DB;     //this aray refers to the asociation between doctors and DB

    //Variables needed for Manager
    Condition* Manager_DoorboyCV;
    Lock* Manager_DoorBoyLock;

    //Variables neede for Doctor
    Condition** arr_DoctorCV;
    Lock** arr_DoctorLock;
    int* arr_DoctorOnBreak;
    Lock* Doc_PrescriptionLock;
    Lock* ConsultancyLock;
    int* Prescription;
    Lock* DocBreakLock;
    int* Doctor_Token;

    int* arr_ConsultancyFee;

    Lock** Doctor_DoorBoyLock;
    Condition** Doctor_DoorBoyCV;

    //Please comment to run**********************************
    int* arr_TockenConsulting;
    int TockenForDoctor;
    int TockenForCashier;

      //variable for cashier
    Lock *cashierLineLock;
        //controls the flow of patient in the lines
    int cashier;
        //number of cashier available
    int *lineSize;
        //array holding the number of patients in the line
    Condition ** cashierCV;
        //condition variable for the cashier patient interaction
    Condition ** cPatientCV;
        //condition variable for cashier interaction to begin
    Lock ** interactionCashierLock;
        // lock for interaction between patient and cashier
    int *cashFlow;
        //shared buffer to communicate
    Lock* CashierBreakLock;  //Lock for cashier to go on break
    Condition* CashierBreakCV; //Condition variable to check whether the
                               //cashier is on a break or not



    Condition **pharmacyControl;

    Lock *pharmaLineLock;
        //Lock the control the flow of patients in clerk  queue
    int clerks;
        //Count of the number of clerks at the window
    int* linePharmaSize;
        //Array holding the number of patients in each line
    Condition ** clerkCV;
        //Array of clerk interaction control variables
    Condition ** patientCV;
        //Array of clerk interaction control variables
    Lock ** interactionLock;
        //Lock for control interaction between patient and pharmacy clerk
    int * pharmacyFlow;
    Condition* PharmacyBreakCV;
    Lock* PharmacyBreakLock;


    int pharmacyTotal;
    Lock *pharmacyTotalLock;

    int cashierTotal;
    Lock *cashierTotalLock;









#endif	/* _ASSIGNMENT1_H */

